name: tests on transformers PEFT main

on:
  push:
    branches: [ main ]

env:
  CI_SLACK_CHANNEL: ${{ secrets.CI_PUSH_MAIN_CHANNEL }}

jobs:
  tests:
    strategy:
      matrix:
        python-version: ['3.9', '3.10', '3.11']
        os: ['ubuntu-latest', 'windows-latest']
      fail-fast: false
    runs-on: ${{ matrix.os }}
    steps:
    - uses: actions/checkout@v3
    - name: Set up Python ${{ matrix.python-version }}
      uses: actions/setup-python@v4
      with:
        python-version: ${{ matrix.python-version }}
        cache: "pip"
        cache-dependency-path: |
            setup.py
            requirements.txt
    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip
        # install PEFT & transformers from source
        pip install -U git+https://github.com/huggingface/peft.git
        pip install -U git+https://github.com/huggingface/transformers.git 
        # cpu version of pytorch
        pip install -e ".[test, diffusers]"
    - name: Test with pytest
      run: |
        make test
    - name: Post to a Slack channel
      if: always()
      id: slack
      #uses: slackapi/slack-github-action@v1.25.0
      uses: slackapi/slack-github-action@6c661ce58804a1a20f6dc5fbee7f0381b469e001
      with:
        # Slack channel id, channel name, or user id to post message.
        # See also: https://api.slack.com/methods/chat.postMessage#channels
        channel-id: ${{ env.CI_SLACK_CHANNEL }}
        # For posting a rich message using Block Kit
        payload: |
          {
            "text": "TRL CI on transformers/PEFT main: ${{ job.status }}\n${{ github.event.pull_request.html_url || github.event.head_commit.url }}",
            "blocks": [
              {
                "type": "section",
                "text": {
                  "type": "mrkdwn",
                  "text": "TRL CI on transformers/PEFT main: ${{ job.status }}\n${{ github.event.pull_request.html_url || github.event.head_commit.url }}"
                }
              }
            ]
          }
      env:
        SLACK_BOT_TOKEN: ${{ secrets.SLACK_CIFEEDBACK_BOT_TOKEN }}
